def __init__(self,argument1, argument2,...): Statements ----------
class Box: def __init__(self,x,y,z): self.L=x self.B=y self.H=z def volume(self): v=self.L*self.B*self.H print("Volume is",v) a=Box(2,3,4) b=Box(4,4,5) a.volume() b.volume()
Volume is 24 Volume is 40
class Worker: def __init__(self,n,w,d): self.name=n self.wages=w self.wdays=d def showData(self): print("Name is",self.name) print("Wages is",self.wages) print("Wdays are",self.wdays) def payment(self): p=self.wages*self.wdays print("Payment is",p) a=Worker("Raja",500,15) a.showData() a.payment()
Name is Raja Wages is 500 Wdays are 15 Payment is 7500
class circle: def __init__(this,n): this.__r=n def area(this): a=3.14*this.__r**2 print("Area is ",a) def circumference(this): c=2*3.14*this.__r print("Circumference is ",c) a=circle(5) a.area() a.circumference()
Area is 78.5 Circumference is31.4
class Employee: def __init__(self,n,s,a): self.name=n self.salary=s self.advance=a def showData(self): print("Name is ",self.name) print("Salary is",self.salary) print("Advance is",self.advance) def payment(self): p=self.salary - self.advance print("Payment is ",p) a=Employee("Amit",25000,5000) b=Employee("Gopal",40000,0) a.showData() a.payment() b.showData() b.payment()
Name is Amit Salary is 25000 Advance is 5000 Payment is 20000 Name is Gopal Salary is 40000 Advance is 0 Payment is 40000